package aip.assignment2.persistence.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Stone
 */
@Entity
@Table(name = "credit_card")
@XmlRootElement
@NamedQueries(
{
	@NamedQuery(name = "CreditCard.findAll", query = "SELECT c FROM CreditCard c"),
	@NamedQuery(name = "CreditCard.findById", query = "SELECT c FROM CreditCard c WHERE c.id = :id"),
	@NamedQuery(name = "CreditCard.findByNumber", query = "SELECT c FROM CreditCard c WHERE c.number = :number"),
	@NamedQuery(name = "CreditCard.findBySecurityCode", query = "SELECT c FROM CreditCard c WHERE c.securityCode = :securityCode"),
	@NamedQuery(name = "CreditCard.findByExpiryMonth", query = "SELECT c FROM CreditCard c WHERE c.expiryMonth = :expiryMonth"),
	@NamedQuery(name = "CreditCard.findByExpiryYear", query = "SELECT c FROM CreditCard c WHERE c.expiryYear = :expiryYear")
})
public class CreditCard implements Serializable
{
	private static final long serialVersionUID = 1L;
	@Id
	@SequenceGenerator(name = "credit_card_id", allocationSize = 1, sequenceName = "credit_card_id_seq")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "credit_card_id")
	@Basic(optional = false)
	@Column(name = "id")
	private Integer id;
	@Size(max = 50)
	@Column(name = "number")
	private String number;
	@Size(max = 10)
	@Column(name = "security_code")
	private String securityCode;
	@Column(name = "expiry_month")
	private Integer expiryMonth;
	@Column(name = "expiry_year")
	private Integer expiryYear;
	@JoinColumn(name = "type", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private CreditCardType type;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "creditCard")
	private List<Customer> customerList;
	public CreditCard()
	{
	}
	public CreditCard(Integer id)
	{
		this.id = id;
	}
	public Integer getId()
	{
		return id;
	}
	public void setId(Integer id)
	{
		this.id = id;
	}
	public String getNumber()
	{
		return number;
	}
	public void setNumber(String number)
	{
		this.number = number;
	}
	public String getSecurityCode()
	{
		return securityCode;
	}
	public void setSecurityCode(String securityCode)
	{
		this.securityCode = securityCode;
	}
	public Integer getExpiryMonth()
	{
		return expiryMonth;
	}
	public void setExpiryMonth(Integer expiryMonth)
	{
		this.expiryMonth = expiryMonth;
	}
	public Integer getExpiryYear()
	{
		return expiryYear;
	}
	public void setExpiryYear(Integer expiryYear)
	{
		this.expiryYear = expiryYear;
	}
	public CreditCardType getType()
	{
		return type;
	}
	public void setType(CreditCardType type)
	{
		this.type = type;
	}
	@XmlTransient
	public List<Customer> getCustomerList()
	{
		return customerList;
	}
	public void setCustomerList(List<Customer> customerList)
	{
		this.customerList = customerList;
	}
	@Override
	public int hashCode()
	{
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}
	@Override
	public boolean equals(Object object)
	{
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof CreditCard))
		{
			return false;
		}
		CreditCard other = (CreditCard) object;
		if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id)))
		{
			return false;
		}
		return true;
	}
	@Override
	public String toString()
	{
		return "aip.assignment2.data.entity.CreditCard[ id=" + id + " ]";
	}
}
